%!TEX root = ../template.tex
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% chapter3.tex
%% NOVA thesis document file
%%
%% Chapter with a short latex tutorial and examples
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\typeout{NT FILE chapter3.tex}%

\makeatletter
\newcommand{\ntifpkgloaded}{%
  \@ifpackageloaded%
}
\makeatother


\chapter{A Short \LaTeX\ Tutorial with Examples}
\label{cha:a_short_latex_tutorial_with_examples}

This Chapter aims at exemplifying how to do common stuff with \LaTeX. We also show some stuff which is not that common! ;)

Please, use these examples as a starting point, but you should always consider using the \emph{Big Oracle} (aka, \href{http://www.google.com}{Google}, your best friend) to search for additional information or al-ternative ways for achieving similar results.

\section{Document Structure} % (fold)
\label{sec:document_structure}

% section document_structure (end)


\section{Dealing with Bibliography} % (fold)
\label{sec:dealing_with_bibliography}

Citing something online~\cite{wiki:shuntingyard,flex,bison}.

% section dealing_with_bibliography (end)


\section{Inserting Tables} % (fold)
\label{sec:inserting_tables}

% section inserting_tables (end)


\section{Importing Images} % (fold)
\label{sec:importing_images}

% section importing_images (end)


\section{Floats, Figures and Captions} % (fold)
\label{sec:floats_figures_and_captions}

% \subsection{Inserting Figures Wrapped with text} % (fold)
% \label{ssec:inserting_images_wrapped_with_text}
%
% You should only use this feature is \emph{really} necessary. This means, you have a very small image, that will look lonely just with text above and below.
%
% In this case, you must use the \verb!wrapfigure! package.  To use \verb!wrapfig!, you must first add this to the preamble:
%
% \begin{wrapfigure}{l}{2.5cm}
%   \centering
%     \includegraphics[width=2cm]{snowman-vectorial}
%   \caption{A snow-man}
% \end{wrapfigure}
%
% \noindent\verb!\usepackage{wrapfig}!\\
% This then gives you access to:\\
% \verb!\begin{wrapfigure}[lineheight]{alignment}{width}!\\
% Alignment can normally be either ``l'' for left, or ``r'' for right. Lowercase ``l'' or ``r'' forces the figure to start precisely where specified (and may cause it to run over page breaks), while capital ``L'' or ``R'' allows the figure to float. If you defined your document as twosided, the alignment can also be ``i'' for inside or ``o'' for outside, as well as ``I'' or ``O''. The width is obviously the width of the figure. The example above was introduced with:
% \lstset{language=TeX, morekeywords={\begin,\includegraphics,\caption}, caption=Wrapfig Example, label=lst:latex_example}
% \begin{lstlisting}
%   \begin{wrapfigure}{l}{2.5cm}
%     \centering
%       \includegraphics[width=2cm]{snowman-vectorial}
%     \caption{A snow-man}
%   \end{wrapfigure}
% \end{lstlisting}

% subsection inserting_images_wrapped_with_text (end)

% section floats_figures_and_captions (end)

\lipsum[1-3]

\begin{figure}[htbp]
  \centering
  \subbottom[One sub-figure\label{fig:leftsubfig}]{%
    \includegraphics[width=0.5\linewidth]{knitting-vectorial}}%
  \subbottom[Another sub-figure\label{fig:rightsubfig}]{%
    \includegraphics[width=0.5\linewidth]{knitting-vectorial}}%
  \caption{A figure with two sub-figures!}
  \label{fig:fig2subfig}
\end{figure}

\textbf{And this is a small text that references the Figure~\ref{fig:fig2subfig} and its Subfigures~\ref{fig:leftsubfig} and~\ref{fig:rightsubfig}.}

\lipsum[1-3]


\section{Text Formatting} % (fold)
\label{sec:text_formatting}

% section text_formatting (end)


\section{Generating PDFs from \LaTeX} % (fold)
\label{sec:generating_pdfs_from_latex}

\subsection{Generating PDFs with pdflatex} % (fold)
\label{ssec:generating_pdfs_with_pdflatex}

You may create PDF files either by using \verb!latex! to generate a DVI file, and then use one of the many DVI-2-PDF converters, such as \verb!dvipdfm!.

Alternatively, you may use \verb!pdflatex!, which will immediately generate a PDF with no intermediate DVI or PS files. In some systems, such as Apple, PDF is already the default format for \LaTeX. I strongly recommend you to use this approach, unless you have a very good argument to go for \verb!latex! + \verb!dvipdfm!.

A typical pass for a document with figures, cross-references and a bibliography would be:
\begin{verbatim}
$ pdflatex template
$ bibtex template
$ pdflatex template
$ pdflatex template
\end{verbatim}
You will notice that there is a new PDF file in the working directory called \verb!template.pdf!. Simple :)

Please note that, to be sure all table of contents, cross-references and bibliographic citations are up-to-date, you must run \verb!latex! once, then \verb!bibtex!, and then \verb!latex! twice.
% section generating_pdfs_with_pdflatex (end)

\subsection{Dealing with Images} % (fold)
\label{sub:dealing_with_images}

You may process the same source files with both \verb!latex! or \verb!pdflatex!. But, if your text include images, you must be careful. \verb!latex! and \verb!pdflatex! accept images in different (exclusive) formats.  For \verb!latex! you may use EPS ou PS figures. For \verb!pdflatex! you may use JPG, PNG or PDF figures.  I strongly recommend you to use PDF figures in vectorial format (do not use bitmap images unless you have no other choice).
% subsection dealing_with_images (end)


\subsection{Dealing with Citations} % (fold)

Para fazer citações, deverá usar-se a chave da referência no ficheiro BibTeX. Se for uma única referência~\cite{Artho04}, usar um ``\verb!~!'' para ligar o \verb!\cite{...}! à palavra que o precede (\ldots\verb!referência~\cite{Artho04}!).  Caso queira fazer múltiplas citações~\cite{Shavit95,Silberschatz06,Moss85}, deverá agrupá-las dentro de um úinico \verb!\cite{...}!.

Note que o ficheiro de bibliografia pode ter tantas entradas quantas quiser. Apenas aquelas cuja chave seja referenciada no texto é que serão incluidas na listagem de bibliografia.


\subsection{Footnotes} % (fold)

Footnotes\footnote{This is a simple footnote.} will be numbered and shown in the bottom of the page.


\subsection{Tables} % (fold)

The Table~\ref{tab:hla:results} illustrates some important concepts associated with table construction:
\begin{asparaenum}[i)]
\item Do not use vertical lines;
\item The caption should be above the table;
\item Use the macros \verb!\toprule!, \verb!\midrule! and \verb!\bottomrule! to make the top, inner and bottom horizontal lines, respectively.
\end{asparaenum}

\bgroup
\rowcolors{1}{}{GhostWhite}
\begin{xltabular}{\textwidth}{Xccccc}
  \caption{Test results summary.}
  \label{tab:hla:results}\\
  \toprule
  \rowcolor{Gainsboro}%
  Test   & Anomalies  & Warnings  & Correct   & Categories            & Missed \\
  \midrule
Connection~\cite{Beckman08}     & 2       & 2          & 1          & \emph{C}              & 1 \\
Coordinates'03~\cite{Artho03}   & 1        & 4          & 1          & \emph{2B, 1C}          & 0 \\
Local Variable~\cite{Artho03}    & 1        & 2          & 1          & \emph{A}              & 0 \\
NASA~\cite{Artho03}              & 1        & 1          & 1          & ---                    & 0 \\
Coordinates'04~\cite{Artho04}    & 1        & 4          & 1          & \emph{3C}              & 0 \\
Buffer~\cite{Artho04}            & 0        & 7          & 0          & \emph{2A, 1B, 2C, 2D}  & 0 \\
Double-Check~\cite{Artho04}      & 0        & 2          & 0          & \emph{1A, 1B}          & 0 \\
StringBuffer~\cite{Flanagan04}  & 1        & 0          & 0          & ---                    & 1 \\
Account~\cite{Praun03}          & 1        & 1          & 1          & ---                   & 0 \\
Jigsaw~\cite{Praun03}            & 1        & 2          & 1          & \emph{C}              & 0 \\
Over-reporting~\cite{Praun03}    & 0        & 2          & 0          & \emph{1A, 1C}          & 0 \\
Under-reporting~\cite{Praun03}  & 1        & 1          & 1          & ---                    & 0 \\
Allocate Vector~\cite{IBM-Rep}  & 1        & 2          & 1          & \emph{C}              & 0 \\
Knight Moves~\cite{Beckman08}   & 1        & 3          & 1          & \emph{2B}              & 0 \\
  \midrule
  \rowcolor{Gainsboro}%
Total                            & 12      & 33        & 10        & 5A, 6B, 10C, 2D       & 2 \\
  \bottomrule
  \end{xltabular}
\egroup

\subsection{Figures} % (fold)

The images inserted in the document must be of good quality, preferably in vector format (vector PDF) and not in \emph{bitmap} (PNG, JPG, etc.). \emph{bitmap} images (Figure~\ref{fig:Figures_Tree_silhouettes-bitmap}) do not scale well and have negative effects on the quality of your document. On the other hand, \emph{vector} images {Figure~\ref{fig:Figures_Tree_silhouettes-vectorial}} scale as much as necessary without degrading the quality of the image.

You should only use \emph{screenshots} for your plots, charts, etc, if you absolutely have no other alternative. Instead of generating a \emph{screenshot}, try using a virtual PDF printer and printing to a PDF file. As a general rule, you will get a vector PDF. Even if your PDF contains images, they will always be of higher or equal quality than what you would get with a \emph{screenshot}.

\begin{figure}[htbp]
  \centering
  \includegraphics[height=1in]{snowman-bitmap}
  \includegraphics[height=3in]{snowman-bitmap}
  \includegraphics[height=6in]{snowman-bitmap}
  \caption{Bitmap image (JPG/PNG)}
  \label{fig:Figures_Tree_silhouettes-bitmap}
\end{figure}

\begin{figure}[htbp]
  \centering
  \includegraphics[height=1in]{snowman-vectorial}
  \includegraphics[height=3in]{snowman-vectorial}
  \includegraphics[height=6in]{snowman-vectorial}
  \caption{Vectorial image (PDF)}
  \label{fig:Figures_Tree_silhouettes-vectorial}
\end{figure}

To combine several figures into a single one… You can then reference the set as Figure~\ref{fig:complete-figure} or the sub-figures separately as~\ref{fig:woolball} and~\ref{fig:cloud}.

\begin{figure}[htbp]
  \centering
    \subbottom[Novelo de lã]{%
    \label{fig:woolball}
    \includegraphics[height=1in]{knitting-vectorial}
    }
\qquad\qquad
    \subbottom[Tempestade com neve]{%
    \label{fig:cloud}
    \includegraphics[height=1in]{snowstorm-vectorial}
    }
  \caption{Exemplo de utilização de \emph{subbottom}}
  \label{fig:complete-figure}
\end{figure}

\section{Equations}

LaTeX is a powerful tool for writing in a mathematical style. It allows you to insert formulas into the text, such as this: $ax^2 + bx + c = 0$. It also allows formulas to be highlighted on a separate line and centered on the page.
\[ x = \frac{-b \pm \sqrt{b^2-4ac}}{2a} \]
or numbererd
\begin{equation}
e = mc^2
\label{eq:1}
\end{equation}
which can latter be referenced as equation~\ref{eq:1}

\newif\ifntlistingsloaded
\ntifpkgloaded{listings}{\ntlistingsloadedtrue}{\ntlistingsloadedfalse}
\newif\ifntmintedloaded
\ntifpkgloaded{minted}{\ntmintedloadedtrue}{\ntmintedloadedfalse}

\ifntlistingsloaded
\section{Test for listings} % (fold)
\label{sec:test_for_listings}

Testing the package “listings“…

\begin{lstlisting}[caption=cap,label=lst:lab,float=htbp]
if(a==b)
  puts("YESS!")
\end{lstlisting}
\fi

\ifntmintedloaded
\section{Test for minted} % (fold)
\label{sec:test_for_minted}

Testing the package “minted“…

\begin{listing}[H]
  \begin{minted}{C}
    if(a==b)
      puts("YESS!")
  \end{minted}
  \caption{Example of a listing.}
  \label{lst:lab}
\end{listing}
\fi

\section{Test for algorithms}
\label{sec:test_for_algorithms}

Uncomment the algorithms source below and add the following to file “\verb!5_packages.tex!”
\begin{verbatim}
  \usepackage{algorithm2e}
  \RestyleAlgo{ruled}
\end{verbatim}
and uncomment
\begin{verbatim}
\ntaddlistof{listofalgorithms}
\end{verbatim}
in file “\verb!8_list_og.tex!”.

% \begin{algorithm}
% $i\gets 10$\;
% \eIf{$i\geq 5$}
% {
%     $i\gets i-1$\;
% }{
%     \If{$i\leq 3$}
%     {
%         $i\gets i+2$\;
%     }
% }
% \caption{This is an algorithm.}
% \end{algorithm}

% section test_for_listings (end)

% \printbibliography[heading=subbibliography, segment=\therefsegment, title={\bibname\ for chapter~\thechapter}]

